package edu.szu.huhanpeng.doodlingFight.controller.showController.manageDone 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessData;
	import edu.szu.huhanpeng.doodlingFight.model.ChessGroupProxy;
	import edu.szu.huhanpeng.doodlingFight.view.StageMed;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import org.puremvc.as3.interfaces.IAsyncCommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.AsyncCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class SrRemoveSuccessChessSc extends AsyncCommand implements IAsyncCommand, INotifier 
	{
		private var _doneArr:Array;
		private var _removeVec:Vector.<IChessData>;		//用于去重
		private static const DELAY:int = 100;
		
		override public function execute(note:INotification):void 
		{
			var groupProxy:ChessGroupProxy = facade.retrieveProxy( ChessGroupProxy.NAME ) as ChessGroupProxy;
			_doneArr = groupProxy.getDone();
			
			_removeVec = new Vector.<IChessData>();
			
			var timer:Timer = new Timer(DELAY, 1);
			timer.addEventListener( TimerEvent.TIMER, onTick );
			timer.start();
		}
		
		private function onTick(e:TimerEvent):void 
		{
			(e.currentTarget as Timer).removeEventListener( TimerEvent.TIMER, onTick );
			var vec:Vector.<IChessData>;
			for (var i:int = 0; i < _doneArr.length; i++) 
			{
				vec = _doneArr[i];
				for (var j:int = 0; j < vec.length; j++) 
				{
					//sendNotification( GlobalConst.noteName.STAGE_REMOVE_CHILD, vec[j].name);
					//去重
					if (_removeVec.indexOf(vec[j]) != -1 ) 
					{
						continue;
					}
					
					_removeVec.push( vec[j] );
					sendNotification( GlobalConst.noteName.REMOVE_CHESS, vec[j] );
				}
			}
			commandComplete();
		}
		
	}

}